
package com.example.KeHuDuan;


import android.content.Context;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;



import java.util.List;

import gson.Test.Video;

public class VideoAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater layoutInflater;
    private List<Video> list;

    public VideoAdapter(Context context, List<Video> list) {
        this.context = context;

        layoutInflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int positon) {
        return this.list.get(positon);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    class VideoHolder {
        TextView VideoId ;
        TextView VideoName ;
        TextView VideoArtist;
        TextView VideoDurtion;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // MusicPlayer music = list.get(position);
        if(convertView == null){
            convertView = layoutInflater.inflate(R.layout.video_item, null);
        }

        VideoHolder holder;

        if (convertView.getTag() != null) {
            holder = (VideoHolder) convertView.getTag();
        } else {
            holder = new VideoHolder();
            holder.VideoId = (TextView) convertView.findViewById(R.id.video_id);
            holder.VideoName = (TextView) convertView.findViewById(R.id.video_title);
            holder.VideoDurtion = (TextView)convertView.findViewById(R.id.video_time);
        }

        convertView.setTag(holder);

        int msec = list.get(position).getDuration();

        holder.VideoId.setText(list.get(position).getId()+1+"");
        holder.VideoName.setText(list.get(position).getVideoName()+"");
        holder.VideoDurtion.setText(((msec)/1000)/60+":"+((msec)/1000)%60+"");

        return convertView;
    }
}
